package be.djdb.utils.table;

/**
* @author Lieven Roegiers
* @copyright 2011
* @from JAVA_mylibs
* @version java 1.4+
*/
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.table.AbstractTableModel;

import be.djdb.Statics;

public class PluginTableModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
	private static ResourceBundle translations;
	private Vector plugins = new Vector();
    private static final String columnNames[] = {"plugins" };
    public int getColumnCount() {
      return columnNames.length;
    }
    /**
     * @param plugins2 
     * @param settings
     */
    public PluginTableModel(Vector plugins2) {
    	//setdata(plugins.gethashtable());
	}

    /*
     *  (non-Javadoc)
     * @see javax.swing.table.AbstractTableModel#getColumnName(int)
     */
    public String getColumnName(int column) {
      return columnNames[column];
    }
    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getRowCount()
     */
    public int getRowCount() {
      return plugins.size();
    }
    /* (non-Javadoc)
     * @see javax.swing.table.TableModel#getValueAt(int, int)
     */
    public Object getValueAt(int row, int column) {
      Object returnValue = null;
      try {
	      if (column == 0) {
	        returnValue = plugins.elementAt(row);
	      }else {
	    	  
		  }
      }catch(ArrayIndexOutOfBoundsException ae){
    	  log(Level.ALL, "<ERROR: getValueAt>ArrayIndexOutOfBoundsException Projectsettings properties emty");
      }catch(Exception e){
    	  log(Level.FINEST, "<ERROR: getValueAt> <FINEST>"+e+"</FINEST>");
      }
      return returnValue;
    }
    /**
     * 
     */
    private void init(){
    	plugins.removeAllElements();
    }
    /* (non-Javadoc)
     * @see javax.swing.table.AbstractTableModel#getColumnClass(int)
     */
    public Class getColumnClass(int c) {
    	if(Statics.FOLLOW){log(Level.WARNING, "colom:"+c);};
        return getValueAt(0, c).getClass();
    }
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if (col != 1) {
            return false;
        } else {
            return true;
        }
    }
    public void setValueAt(Object value, int row, int col) {
        if (Statics.DEBUG){log(Level.FINE, "<SET VALUE> <POS:"+row+","+col+"|TO:"+value+"//"+value.getClass()+">");}
    }
	private static  void log(Level level, String msg ){
	    String tag ="<>>>>*"+Statics.LIBNAME+"-"+Statics.COPYRIGHTBY+"*<<<<>StreamManipulator";
	    Logger.getLogger(PluginTableModel.class.getName()).log(level, tag + msg);
	}
    private void printDebugData() {
        int numRows = getRowCount();
        int numCols = getColumnCount();
        log(Level.FINEST,"-<start>-");
        for (int i=0; i < numRows; i++) {
            log(Level.FINEST,"    row " + i + ":");
            for (int j=0; j < numCols; j++) {
                log(Level.FINEST," + data[i][j]");
            }  
        }
        log(Level.FINEST,"-<end>-");
    }
    private synchronized void setdata(Hashtable<Object, Object> table) {
        Set set = table.entrySet();
        Iterator it = set.iterator();
        init();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            //plugins.addElement( entry.getKey());
            
       }
       //fireTableDataChanged();
    }

}
